from uliweb.form import *
from uliweb.i18n import ugettext_lazy as _

class GroupCreateForm(Form):
    form_buttons = Submit(value=_('Create'), _class=".submit")

    name = StringField(label=_('Group Name:'), required=True)
    caption = StringField(label=_('Group Caption:'), required=True)
    description = TextField(label=_('Description'))
    managers = ListField(label=_('Manager names'))
    
    def validate_name(self, data):
        from uliweb.orm import get_model
        
        Group = get_model('group')
        group = Group.get(Group.c.name==data)
        if group:
            raise ValidationError, 'Group "%s" is already existed!' % data
    
class GroupEditForm(Form):
    form_buttons = Submit(value=_('Save'), _class=".submit")

    caption = StringField(label=_('Group Caption:'), required=True)
    description = TextField(label=_('Description'))
    managers = ListField(label=_('Manager names'))
